package web_report

import (
	"math/rand"
	"strconv"
	"strings"
)

// 通用岗位报告

type CommonWebReport struct {
	*DefaultWebReport
}

func (c *CommonWebReport) GetTotalScore() float64 {
	return c.avgLanguageScore*0.2 +
		c.avgThemeScore*0.4 +
		c.evaluateResp.EvalScore*100*0.2 +
		c.logicScoreCache.Avg*0.2
}

func (c *CommonWebReport) GetGeneralData() *ScoreChart {
	chartsData := make([]LabelValue, 0)
	for _, pos := range c.evaluateResp.PosWordScore.General {
		score := 60 + int(pos[1].(float64)*100*25/100)
		score += rand.Intn(10) + 1
		chartsData = append(chartsData, LabelValue{
			Label: pos[0].(string),
			Value: score,
		})
	}
	for _, neg := range c.evaluateResp.NegScoreDict.General {
		score := int(neg[1].(float64) * 100 * 30 / 100)
		score += rand.Intn(10) + 1 // 通用岗位增加随机分数
		chartsData = append(chartsData, LabelValue{
			Label: neg[0].(string),
			Value: score,
		})
	}
	return &ScoreChart{
		Score:     int(c.evaluateResp.LabelScore.General * 100),
		ChartData: chartsData,
	}
}

func (c *CommonWebReport) GetGuideData() (interface{}, error) {
	guide := &CommonGuide{
		Instruction: "",
		Performance: "",
		Promotion:   "",
	}
	careerId := strconv.Itoa(int(c.Session.CareerID))
	totalScore := c.Session.TotalScore
	switch {
	case totalScore > 75:
		guide.Performance = SuggestComments[careerId]["面试表现"]["A"]
		//guide.Promotion = SuggestComments[careerId]["提升建议"]["A"]
	case totalScore >= 50:
		guide.Performance = SuggestComments[careerId]["面试表现"]["B"]
		//guide.Promotion = SuggestComments[careerId]["提升建议"]["B"]
	case totalScore >= 25:
		guide.Performance = SuggestComments[careerId]["面试表现"]["C"]
		//guide.Promotion = SuggestComments[careerId]["提升建议"]["C"]
	case totalScore >= 0:
		guide.Performance = SuggestComments[careerId]["面试表现"]["D"]
		//guide.Promotion = SuggestComments[careerId]["提升建议"]["D"]
	}
	guide.Instruction = SuggestComments[careerId]["评测说明"]["A"]
	glm2Guide, err := c.GetGlm2Guide()
	if err != nil {
		return nil, err
	}
	guide.Glm2Suggest = glm2Guide
	guide.Promotion = glm2Guide.(string)
	return guide, nil
}

func (c *CommonWebReport) GetSlotValueObj() *SlotValue {
	negLabels := make([]string, 0)
	for _, negLabel := range c.GetNegGeneralData() {
		negLabels = append(negLabels, negLabel.Label)
	}
	return &SlotValue{
		CareerName:    "",
		NegLabels:     strings.Join(negLabels, "]["),
		AnswerContent: c.allAnswerContent,
	}
}
